package com.htfyun.ft.fragment.engineer;

import android.content.Context;

import com.htfyun.ft.FTApplication;
import com.htfyun.ft.R;
import com.htfyun.ft.config.NVRomKeysAttr;
import com.htfyun.ft.device.DeviceAttr;

import java.util.ArrayList;
import java.util.List;

import androidx.fragment.app.Fragment;

/**
 * Created by sst on 2018/7/11.
 */

public enum EngineerFragmentItemsEnum {

    assist(R.string.engineer_test_assist, null, FragmentAssistSettings.class),
    ft_force_fail(R.string.ft_force_failed, null,  FragmentFTForceFailed.class),
    update_image(R.string.engineer_update_image, null,  FragmentUpdateImage.class),
    night_display(R.string.engineer_test_night_display, NVRomKeysAttr.night_display,  FragmentNightDisplay.class),
    hard_disk(R.string.engineer_test_hard_disk, NVRomKeysAttr.hard_disk,  FragmentHardDisk.class),
    hard_disk_rw(R.string.engineer_test_hard_disk_rw, NVRomKeysAttr.hard_disk,  FragmentHardDiskRW.class),
    install_wl(R.string.engineer_test_white_list_install, NVRomKeysAttr.white_list_install,  FragmentWhiteListInstall.class),
    uninstall_wl(R.string.engineer_test_white_list_uninstall, NVRomKeysAttr.white_list_uninstall,  FragmentWhiteListUninstall.class),
    net_wl(R.string.engineer_test_white_list_net, NVRomKeysAttr.white_list_net,  FragmentWhiteListNet.class),
//    ftSettings(R.string.main_btn_test_aging, FragmentFTSettings.class),
    servo(R.string.ft_item_servo, NVRomKeysAttr.servo, FragmentServo.class),
    led(R.string.led_tips, NVRomKeysAttr.led_breath, FragmentLed.class),
    key(R.string.ft_item_key,  NVRomKeysAttr.keys, FragmentKey.class),
    aging(R.string.main_btn_test_aging, null, FragmentAgingSettings.class),

    ;
    private final int nameResId;
    private final NVRomKeysAttr nvRomKeysAttr;
    private final Class<? extends Fragment> fragmentClass;

    EngineerFragmentItemsEnum(int nameResId, NVRomKeysAttr attr, Class<? extends Fragment> cls) {
        this.nameResId = nameResId;
        nvRomKeysAttr = attr;
        this.fragmentClass = cls;
    }

    public String getName() {
        final Context context = FTApplication.getContext();
        if (nameResId > 0) {
            return context.getString(nameResId);
        }
        return "";
    }

    public Class<? extends Fragment> getFragmentClass() {
        return fragmentClass;
    }

    ////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////
    private static List<EngineerFragmentItemsEnum> supportedEngineerItemList = null;
    public static List<EngineerFragmentItemsEnum> getSupportedEngineerItemList() {
        if (supportedEngineerItemList != null) {
            return supportedEngineerItemList;
        }
        supportedEngineerItemList = new ArrayList<>();
        supportedEngineerItemList.clear();
        for (EngineerFragmentItemsEnum itemsEnum : EngineerFragmentItemsEnum.values()) {
            if (itemsEnum.getFragmentClass() == null) {
                continue;
            }

            if (!DeviceAttr.isNVRomKeySupported(itemsEnum.nvRomKeysAttr)) {
                continue;
            }
            supportedEngineerItemList.add(itemsEnum);
        }

        return supportedEngineerItemList;
    }


}
